﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YK.Framework.Logging;

namespace YK.Framework.Mvc
{
    public class HandleErrorLogAttribute : FilterAttribute, IExceptionFilter
    {
        public void OnException(ExceptionContext filterContext)
        {
            Logger logger = Logger.GetLogger(filterContext.Controller.GetType());

            logger.Error(filterContext.Exception);

            filterContext.Controller.ViewData["Error"] = filterContext.Exception;
            filterContext.Result = new ViewResult()
            {
                ViewName = "Error",
                ViewData = filterContext.Controller.ViewData,
            };

            filterContext.ExceptionHandled = true;
        }

    }
}